package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.ClazzOption;
import com.itheima.pojo.GenderOption;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    //    接口描述：统计各个职位的员工人数
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public JobOption getEmpJobData() {
        //map集合中string类型 代表查询出来的字段名，object类型 代表字段值
        /*
        比如查询出来的pos字段的值有讲师，班主任等是一个集合
            map pos = 讲师 ,total=2
         */
        List<Map<String, Object>> list = empMapper.countEmpJobData();
        List<Object> jobList = list.stream().map(s -> s.get("pos")).toList();
        List<Object> dataList = list.stream().map(s -> s.get("total")).toList();
        return new JobOption(jobList, dataList);
    }

    //统计员工性别信息
    @Override
    public List<GenderOption> getEmpGenderData() {

        List<GenderOption> list = empMapper.countEmpGenderData();
        return list;

        //怎么获取到name和value 最终封装成一个map
//        {"name": "男性员工","value": 5},
//        {"name": "女性员工","value": 6}

    }

    //    接口描述：统计学员的学历信息
    @Override
    public List<Map> getStutDegreeData() {
        return studentMapper.getStutDegreeData();

    }

    /**
     * 统计每一个班级的人数
     */
    @Override
    public ClazzOption getStutCountData() {
        List<Map<String, Object>> list = studentMapper.getStutCountData();


        List<Object> clazzList = list.stream().map(s -> s.get("cname")).toList();
        List<Object> dataList = list.stream().map(s -> s.get("value")).toList();
        return new ClazzOption(clazzList, dataList);

    }
}
